import java.util.ArrayList;

public class Student implements Comparable<Student> {
    private String id;
    private String name;
    private int age;
    private ArrayList<Double> scores;

    public Student(String id, String name, int age, ArrayList<Double> scores) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.scores = scores;
    }

    public double totalScore() {
        double sum = 0;
        for (double score : scores) {
            sum += score;
        }
        return sum;
    }

    public double average() {
        if (scores.isEmpty()) return 0;
        return totalScore() / scores.size();
    }

    @Override
    public int compareTo(Student other) {
        return Double.compare(other.totalScore(), this.totalScore());
    }

    @Override
    public String toString() {
        StringBuilder scoreStr = new StringBuilder();
        for (double score : scores) {
            scoreStr.append(String.format("%.1f ", score));
        }
        return String.format("%-10s%-8s%-6d%-20s%-8.1f%-8.1f",
                id, name, age, scoreStr, totalScore(), average());
    }

    // Getter 方法
    public String getId() {
        return id;
    }
}    